package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Model0422;
import com.lecture.java8.excel.dyr.model.Result0422_2;
import com.lecture.java8.excel.dyr.model.Result0422_3;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0422_1 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0422\\1\\";


        String result1 = dir + "全要素生产率.xlsx";
        DemoDataListener<Result0422_2> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(result1, Result0422_2.class,dataResultListener).sheet().doRead();
        //全要素生产率
        List<Result0422_2> resultList = dataResultListener.getDataList();
        Map<String,Result0422_2> map1 = new HashMap<>();
        for (Result0422_2 result : resultList) {
            map1.put(result.getA() + "-" + result.getB(),result);
        }

        String result2 = dir + "新建 Microsoft Excel 工作表.xlsx";
        DemoDataListener<Result0422_3> resultDataListener2 = new DemoDataListener<>();
        EasyExcel.read(result2, Result0422_3.class,resultDataListener2).sheet().doRead();
        //全要素生产率
        List<Result0422_3> resultList2 = resultDataListener2.getDataList();
        Map<String,Result0422_3> map2 = new HashMap<>();
        for (Result0422_3 result : resultList2) {
            map2.put(result.getA() + "-" + result.getB(),result);
        }


        String dataResultFileName = dir + "2011年-2022年制造业企业数据搜集.xlsx";
        DemoDataListener<Model0422> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Model0422.class,dataListener).sheet().doRead();
        List<Model0422> dataList = dataListener.getDataList();

        for (Model0422 model : dataList) {
            Result0422_2 r1 = map1.get(model.getA() + "-" + model.getYear());
            if (r1 != null) {
                model.setK(r1.getC());
                model.setL(r1.getD());
                model.setM(r1.getE());
                model.setN(r1.getF());
                model.setO(r1.getG());
                model.setP(r1.getH());
            }

            Result0422_3 r2 = map2.get(model.getYear() + "-" + model.getI());
            if (r2 != null) {
                model.setJ(r2.getD());
            }

        }

        EasyExcel.write(dir + "result2.xlsx", Model0422.class)
                .sheet("a").doWrite(dataList);
    }
}
